Fix template for library packages#1
Conversation
- Add [build-system] with hatchling - Add [tool.hatch.build.targets.wheel] packages config - Fix make init to handle hyphenated names (dir uses _, name uses -) - Fix make init to update ci.yml coverage module name - Fix make init to remove template main.py for library packages - Switch [project.optional-dependencies] dev to [dependency-groups] dev - Add authors, license fields to pyproject.toml - Add __version__ to __init__.py - Remove libvips/xvfb/unar from CI setup action - Update sync commands from --all-extras to --group dev Amp-Thread-ID: https://ampcode.com/threads/T-019cec73-4e6a-732e-acf1-30c4bfec4195 Co-authored-by: Amp <amp@ampcode.com>
|
Warning Rate limit exceeded
⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughMakefile init now derives PKG_DIR from NAME and renames package; pyproject switches to Hatchling and adds a dev dependency group; CI/setup action adjusts system packages and uses Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
📝 Coding Plan
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
Makefile (1)
53-54:⚠️ Potential issue | 🟡 MinorThe
runtarget will fail afterinitremovesmain.py.For library packages,
main.pyis deleted during initialization (lines 25-28), but theruntarget still references it. Consider removing this target or documenting that it's only for application templates.🛠️ Option: Remove run target for library template
venv: ## Create virtual environment uv venv - -run: ## Run the app - python main.pyOr update the help text to clarify it's for application templates only.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@Makefile` around lines 53 - 54, The Makefile's run target (run:) still executes python main.py but init removes main.py for library templates, causing run to fail; update the Makefile by either removing the run target entirely for library templates or conditionally document/guard it so it only exists for application templates—modify the run target or the init logic and the Makefile help text to ensure run does not reference main.py when init deletes it, and mention the change near the init and run target declarations to keep behavior consistent.
🧹 Nitpick comments (1)
example_module/__init__.py (1)
2-3: Consider using dynamic versioning to avoid dual maintenance.The version
"0.1.0"is now defined in both__init__.pyandpyproject.toml. When bumping versions, both files must be updated in sync.Hatchling supports reading the version from
__version__dynamically. Alternatively, this dual-source approach is acceptable if you prefer explicit control in the template.♻️ Optional: Configure dynamic versioning in pyproject.toml
[project] name = "python-starter-template" -version = "0.1.0" +dynamic = ["version"] description = "Python starter template with best practices"And add:
[tool.hatch.version] path = "example_module/__init__.py"🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@example_module/__init__.py` around lines 2 - 3, The package version is duplicated: __version__ is hardcoded in __init__.py while pyproject.toml contains the canonical version; switch to dynamic versioning by configuring Hatch to read the package's __version__ (i.e., add a [tool.hatch.version] entry that points at your package to use the __version__ symbol) so you only maintain the version in one place, or conversely remove the duplicate from pyproject.toml and keep the single source as __version__ in __init__.py — update the pyproject.toml Hatch config accordingly to reference the __version__ symbol.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@Makefile`:
- Around line 53-54: The Makefile's run target (run:) still executes python
main.py but init removes main.py for library templates, causing run to fail;
update the Makefile by either removing the run target entirely for library
templates or conditionally document/guard it so it only exists for application
templates—modify the run target or the init logic and the Makefile help text to
ensure run does not reference main.py when init deletes it, and mention the
change near the init and run target declarations to keep behavior consistent.
---
Nitpick comments:
In `@example_module/__init__.py`:
- Around line 2-3: The package version is duplicated: __version__ is hardcoded
in __init__.py while pyproject.toml contains the canonical version; switch to
dynamic versioning by configuring Hatch to read the package's __version__ (i.e.,
add a [tool.hatch.version] entry that points at your package to use the
__version__ symbol) so you only maintain the version in one place, or conversely
remove the duplicate from pyproject.toml and keep the single source as
__version__ in __init__.py — update the pyproject.toml Hatch config accordingly
to reference the __version__ symbol.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 58120ce8-5b64-48d5-959d-e16635fa278a
📒 Files selected for processing (4)
.github/actions/setup/action.ymlMakefileexample_module/__init__.pypyproject.toml
Automated fixes applied by ralph_loop.sh Model: zai-coding-plan/glm-4.7 Phase: 0
Add warning banners to README.md and AGENTS.md to clearly indicate template files that need manual updates after initialization. Replace hardcoded "example_module" references with [[MODULE_NAME]] placeholders for easier customization. Create comprehensive POST_INIT_CHECKLIST.md and TEMPLATE_GUIDE.md to guide users through the initialization process. Enhance make init output with detailed summary of automated changes and manual updates required. Add placeholder comments in CI workflow and update CHANGELOG.md to document template improvements. This addresses confusion about placeholder text and unclear instructions by making it explicit what needs to be updated after running make init.
Welcome to Codecov 🎉Once you merge this PR into your default branch, you're all set! Codecov will compare coverage reports and display results in all future pull requests. ℹ️ You can also turn on project coverage checks and project coverage reporting on Pull Request comment Thanks for integrating Codecov - We've got you covered ☂️ |
There was a problem hiding this comment.
Actionable comments posted: 8
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (2)
README.md (2)
40-40:⚠️ Potential issue | 🟠 MajorQuick Start/Daily commands reference removed file.
Lines 40 and 68 run
python main.pyafter initialization, but library init removesmain.py. This is a broken default path for first-time users.Suggested doc fix
-# Run your application -python main.py --name World --value 42 +# Run tests (library default workflow) +pytestAlso applies to: 68-68
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@README.md` at line 40, The README still instructs users to run "python main.py" which no longer exists after the library initialization; update both occurrences (the example at line ~40 and the one at ~68) to the correct runtime invocation for this project (e.g., replace "python main.py --name World --value 42" with the actual entrypoint such as "python -m <module_name> --name World --value 42" or the new script name), and ensure the Quick Start example matches the package's current entrypoint or installation instructions so first-time users can run the app successfully.
31-31:⚠️ Potential issue | 🟠 MajorFix
uv synccommand to use--groupinstead of--all-extras.Lines 31 and 54 use
uv sync --all-extras, but the project uses[dependency-groups]in pyproject.toml. The--all-extrasflag doesn't apply to dependency groups, so this command won't install test/lint tools from the dev group. Useuv sync --group devinstead.Suggested fix
-uv sync --all-extras +uv sync --group devAlso applies to: 54-54
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@README.md` at line 31, Replace the incorrect use of the Poetry/uvicorn sync flag: find occurrences of the command string "uv sync --all-extras" (used in README examples) and change them to use the dependency-group flag for the dev group, i.e. "uv sync --group dev"; update both occurrences (the ones noted around the README examples) so the dev dependency group from pyproject.toml is installed correctly.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.github/actions/setup/action.yml:
- Around line 10-11: The CI step runs apt-get as a non-root user and must use
sudo; update the action.yml step that contains the two commands "apt-get update
-qq" and "apt-get install -y -qq ca-certificates curl git python3 python3-venv
libatomic1 gnupg" to prepend sudo to both invocations so the package
update/install runs with elevated privileges in GitHub-hosted runners.
In `@AGENTS.md`:
- Line 6: Update the AGENTS.md guidance that currently assumes a main.py
entrypoint: where text mentions "The entrypoint is `main.py`" (and the similar
reference later) change it to explain that `make init` may remove main.py for
library packages and that the module directory may be a library without an
entrypoint; state the default behaviors for apps versus libraries (e.g., apps
use `main.py` as entrypoint, libraries have no entrypoint and should expose
package API) and mention contributors should create a new package directory or
add an entrypoint if they need CLI/startup files.
In `@CHANGELOG.md`:
- Line 35: Replace the placeholder date in the release header "## [0.1.0] -
2024-01-XX" with a concrete ISO date (e.g., "## [0.1.0] - 2024-01-15") or remove
the date portion entirely (leaving "## [0.1.0]") if the release date is not yet
finalized; update the header text in CHANGELOG.md where the string "## [0.1.0] -
2024-01-XX" appears.
In `@POST_INIT_CHECKLIST.md`:
- Around line 24-27: The checklist's example for replacing `[[MODULE_NAME]]` is
confusing because it repeats `my_project` and omits a hyphenated project-name
example; update the example under the "Replace `[[MODULE_NAME]]` references"
bullet so it shows both forms (e.g., project name with hyphen like `my-project`
and package/module directory name like `my_project`) and clarify which form is
used where, referencing the `[[MODULE_NAME]]` placeholder text and the example
text currently showing `my_project`.
In `@README.md`:
- Line 95: Update the README line that currently reads "├── [[MODULE_NAME]]/
# Main package (rename via make init)" to clarify that placeholder replacement
is a manual step: change the parenthetical to something like "(replace
[[MODULE_NAME]] manually as described in the init checklist)" or point to the
specific "init" checklist/section; reference the exact token [[MODULE_NAME]] and
the phrase "make init" so reviewers can find and update the README entry and any
related init instructions to avoid implying automatic renaming.
In `@TEMPLATE_GUIDE.md`:
- Around line 84-86: The guide currently tells users to run "python main.py"
after initialization but earlier sections (and later notes) indicate main.py is
removed for library-package setups, causing a dead-end; update TEMPLATE_GUIDE.md
to either remove the "python main.py" run step or make it conditional by
checking the project type (e.g., add text like "If this is an application with
an entrypoint, run `python main.py`; if you initialized a library/package (no
main.py), skip this step and follow the publishing or import instructions"), and
reference the entrypoint filename "main.py" and the
initialization/library-package notes so the doc flow remains consistent.
- Around line 117-140: Update the fenced code block that shows the project tree
in TEMPLATE_GUIDE.md to include a language specifier (use "text") after the
opening triple backticks so markdownlint MD040 is satisfied; locate the block
that begins with ``` and the directory tree (python-starter-template/ ...
TEMPLATE_GUIDE.md) and change the opening fence to ```text.
- Around line 52-53: Update the command recommendation in TEMPLATE_GUIDE.md:
replace the existing "uv sync --all-extras" suggestion with guidance to run "uv
sync" for the default dev group, or "uv sync --all-groups" (or "uv sync --group
<name>") when you need dependency groups beyond extras; ensure the doc text
around the uv sync invocation explains that --all-extras only installs extras
and will skip packages declared under [dependency-groups].
---
Outside diff comments:
In `@README.md`:
- Line 40: The README still instructs users to run "python main.py" which no
longer exists after the library initialization; update both occurrences (the
example at line ~40 and the one at ~68) to the correct runtime invocation for
this project (e.g., replace "python main.py --name World --value 42" with the
actual entrypoint such as "python -m <module_name> --name World --value 42" or
the new script name), and ensure the Quick Start example matches the package's
current entrypoint or installation instructions so first-time users can run the
app successfully.
- Line 31: Replace the incorrect use of the Poetry/uvicorn sync flag: find
occurrences of the command string "uv sync --all-extras" (used in README
examples) and change them to use the dependency-group flag for the dev group,
i.e. "uv sync --group dev"; update both occurrences (the ones noted around the
README examples) so the dev dependency group from pyproject.toml is installed
correctly.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 43699b56-b5f7-4e2b-9979-94db9c089f4a
⛔ Files ignored due to path filters (1)
uv.lockis excluded by!**/*.lock
📒 Files selected for processing (8)
.github/actions/setup/action.yml.github/workflows/ci.ymlAGENTS.mdCHANGELOG.mdMakefilePOST_INIT_CHECKLIST.mdREADME.mdTEMPLATE_GUIDE.md
✅ Files skipped from review due to trivial changes (1)
- .github/workflows/ci.yml
🚧 Files skipped from review as they are similar to previous changes (1)
- Makefile
| # Run your application (if you have an entrypoint) | ||
| python main.py | ||
| ``` |
There was a problem hiding this comment.
Contradictory entrypoint guidance after initialization.
Line 85 instructs python main.py, but Lines 100 and 132 indicate main.py is removed for library-package initialization. This will produce a dead-end flow immediately after setup.
Suggested doc fix
-# Run your application (if you have an entrypoint)
-python main.py
+# Run your package tests (library default)
+pytest
+
+# If you later add an entrypoint script, run that script instead.Also applies to: 100-100, 132-132
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@TEMPLATE_GUIDE.md` around lines 84 - 86, The guide currently tells users to
run "python main.py" after initialization but earlier sections (and later notes)
indicate main.py is removed for library-package setups, causing a dead-end;
update TEMPLATE_GUIDE.md to either remove the "python main.py" run step or make
it conditional by checking the project type (e.g., add text like "If this is an
application with an entrypoint, run `python main.py`; if you initialized a
library/package (no main.py), skip this step and follow the publishing or import
instructions"), and reference the entrypoint filename "main.py" and the
initialization/library-package notes so the doc flow remains consistent.
- Add sudo to apt-get commands in CI action.yml - Clarify main.py entrypoint behavior for apps vs libraries in AGENTS.md - Fix uv sync commands to use --group dev instead of --all-extras - Replace placeholder date in CHANGELOG.md - Improve MODULE_NAME example with hyphenated project names - Clarify [[MODULE_NAME]] is manually replaced in README.md - Make python main.py execution conditional in docs - Add language specifier to code fence in TEMPLATE_GUIDE.md
There was a problem hiding this comment.
Actionable comments posted: 2
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
README.md (1)
106-106:⚠️ Potential issue | 🟡 MinorMake
main.pynote consistent with library-default flow.Line 106 presents
main.pyas a standard file, but library initialization removes it by default. Consider annotating this line similarly to other sections (e.g., “entrypoint for apps; removed for library packages”).🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@README.md` at line 106, Update the README entry for main.py to match the library-default flow by annotating it as an application entrypoint that is removed for library packages; specifically modify the line referencing "main.py" (the symbol main.py) to read something like "main.py — application entrypoint; removed for library packages" so it matches the other section annotations.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@POST_INIT_CHECKLIST.md`:
- Line 8: Update the checklist line that currently reads "✅ Renames the module
directory from `example_module` to your project name" to clarify that package
directory names are underscore-normalized for hyphenated project names (e.g.,
"my-project" → "my_project") and make the wording consistent with the later
phrasing used elsewhere in the document (match the language that explains
hyphen-to-underscore normalization).
In `@TEMPLATE_GUIDE.md`:
- Line 43: Update the phrasing that references the package directory to say
"package directory/module name" instead of implying the directory is the exact
project name, and add an explicit hyphen-to-underscore example such as
"my-project → my_project"; reference the existing wording around
`example_module` and the sentence at lines 43 and 97 to replace the ambiguous
text and insert the `my-project` → `my_project` example for consistency.
---
Outside diff comments:
In `@README.md`:
- Line 106: Update the README entry for main.py to match the library-default
flow by annotating it as an application entrypoint that is removed for library
packages; specifically modify the line referencing "main.py" (the symbol
main.py) to read something like "main.py — application entrypoint; removed for
library packages" so it matches the other section annotations.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 134fa7c6-1be1-4528-bd91-751ded76e665
📒 Files selected for processing (6)
.github/actions/setup/action.ymlAGENTS.mdCHANGELOG.mdPOST_INIT_CHECKLIST.mdREADME.mdTEMPLATE_GUIDE.md
✅ Files skipped from review due to trivial changes (1)
- CHANGELOG.md
🚧 Files skipped from review as they are similar to previous changes (1)
- .github/actions/setup/action.yml
Debian containers run as root by default, so sudo is not available. Reverting previous change that added sudo to apt-get commands.
- Clarify that hyphenated project names are normalized to underscores in package directory names - Add explicit example (my-project → my_project) in POST_INIT_CHECKLIST.md and TEMPLATE_GUIDE.md - Update main.py annotation to note it's removed for library packages
Phase 0 of package consolidation plan.
Changes:
[build-system]with hatchling souv buildworks[tool.hatch.build.targets.wheel]packages configmake initto handle hyphenated names (dir uses_, project name uses-)make initto update ci.yml coverage module namemake initto remove template main.py for library packages[project.optional-dependencies] devto[dependency-groups] devauthors,licensefields to pyproject.toml__version__to__init__.pyVerified:
make init NAME=longbox-commons→ clean project that passesuv build+uv pip install .Summary by CodeRabbit
Build & Infrastructure
New Features
Documentation
Chores